package test;

import javax.xml.crypto.Data;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class CourseWork {
    public static void main(String[] args) throws UnsupportedEncodingException, ParseException {
        int  year,month,day,hour,minute,second;
        PrintStream  ps  =  new  PrintStream(System.out,true,"utf-8");
        Scanner  sc  =  new  Scanner(System.in,"UTF-8");
        ps.print("输入年:");
        year  =  sc.nextInt();
        ps.print("输入月:");
        month  =  sc.nextInt();
        ps.print("输入日:");
        day  =  sc.nextInt();
        ps.print("输入时:");
        hour  =  sc.nextInt();
        ps.print("输入分:");
        minute  =  sc.nextInt();
        ps.print("输入秒:");
        second  =  sc.nextInt();
        MyCalendar  mc  =  new  MyCalendar(year,  month,day,hour,minute,second);
        mc.formatDate();//第一种格式化输出
        mc.yearDay();//计算今年已经过了多少天，还剩多少天
    }
}
class  MyCalendar {//日历类
//成员变量  年  月  日  时  分  秒
    //todo
public int year;
    public int month;
    public int day;
    public int hour;
    public int minute;
    public int second;

    //  创建成员变量——默认的日历对象
    Calendar calendar  =Calendar.getInstance();
    MyCalendar(int  year,int  month,int  day,int  hour,int  minute,int  second) {//构造方法
        //将成员变量赋值
        this.year=year;
        this.month=month;
        this.day=day;
        this.hour=hour;
        this.minute=minute;
        this.second=second;
    }
    void  formatDate()  throws  UnsupportedEncodingException {
        PrintStream ps = new PrintStream(System.out, true, "utf-8");
        //  直接使用set设置日期
        calendar.set(year,month-1,day,hour,minute,second);
        //  通过日历获得Date对象
        Date  date  =calendar.getTime();
        //实例化日期格式化对象
        DateFormat df = new SimpleDateFormat("日期:"+"yyyy-MM-dd"+".时间:"+"hh:mm:ssa");
        ps.println(df.format(date));
    }
    void  yearDay() throws UnsupportedEncodingException {//计算今年已经过去多少天，还剩多少天
        //todo
        //  通过日历获得Date对象
        Date  date  =calendar.getTime();
        DateFormat df=new SimpleDateFormat("yyyy-MM-dd");//指定格式时间转换
        try {
            date=df.parse(df.format(date));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        long datetime=date.getTime();//时间转换成毫秒值
        Date data= null;
        try {
            data = new SimpleDateFormat("yyyy-MM-dd").parse(calendar.get(Calendar.YEAR)+"-"+"01-01");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long todaytime=data.getTime();//获取当前日期毫秒值
        long Difference=datetime-todaytime;//差值
        System.out.println("今年已经过去"+Difference/1000/60/60/24+"天");
        int dayNUmber = (int) (LocalDate.of(year, 1, 1).lengthOfYear()-Difference/1000/60/60/24);
        System.out.println("今年还剩下"+dayNUmber+"天");
    }
}
